<?php
include_once ("httpsqs/httpsqs_client.php");
$httpsqs_host = "localhost";
$httpsqs_port = "1218";
$httpsqs_auth = "";
$httpsqs_charset = "utf-8";

$httpsqs = new httpsqs($httpsqs_host, $httpsqs_port, $httpsqs_auth, $httpsqs_charset);
$wsn_status = "STOP";
$wsn_action = "START";
$msg = "";

if ($_POST["action"] == "START") {
	//put the service into the queue
	$timestamp = time();
	$msg = $_POST["action"] . " " . $_POST["port"] . " " . $_POST["timeout"] . " " . $_POST["duration"] . " " . $timestamp;
	$result = $httpsqs->put("java_php_request", $msg);

	//store the collection history

	$con = mysql_connect("localhost", "root", "bytewalla5");
	if (!$con) {
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("wsn", $con);

	$sqlstr = "insert into collecthistory(timestamp,port,duration) values('" . $timestamp . "'," . (int) $_POST["port"] . "," . (int) $_POST["duration"] . ")";
	$done = mysql_query($sqlstr);
	mysql_close($con);
}
header("Location: collecthistory.php");
?>